import logging

from selenium import webdriver
import time
# from Page.Page import Page
from Page.Page1 import Page1
from Page.Page2 import Page2
# from selenium.webdriver.common.by import By
import unittest
from Public.common import Common
from ddt import ddt, file_data, data, unpack


@ddt()
class TestCase(unittest.TestCase):

    def setUp(self):
        Common().Log()
        # self.driver = webdriver.Firefox()
        # self.driver = webdriver.Edge()
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()


    def tearDown(self):
        time.sleep(5)
        self.driver.quit()

    # def test_item_01(self):
    #     po = Page(self.driver)
    #     po.Item_user_register()
        # 断言注册成功
        # dy1 = self.driver.find_element(By.XPATH, '/html/body/div[5]/p').text
        # self.assertIn('注册成功', dy1)
    @file_data(rf'D:\zhuangaoliu\UI_zdh_zg6_lx\Data\login.json')
    def test_item_02(self, username, password, casename, expected):
        logging.info('case start')
        logging.info(casename+'****'+expected)
        print(casename+'****'+expected)
        po = Page1(self.driver)
        po.Item_user_login(username, password)

        if '正确' in casename:
            time.sleep(2)
            alert = self.driver.switch_to.alert
            dy1 = alert.text
            self.assertIn(expected, dy1)
            alert.accept()

        # # 断言登录成功，成功跳转到物品列表页面
        # dy1 = self.driver.find_element(By.XPATH, '//main[@class="el-main main"]/h2[text()="物品列表"]').text
        # self.assertIn('物品列表', dy1)


        logging.info('end start')

    # def test_item_03(self):
    #     po = Page2(self.driver)
    #     po.seatch_luoji_01()






if __name__ == '__main__':
    unittest.main()







